﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYAuto.MonitorData.Chitunion.Bll.MonitorNotice.Enum;
using XYAuto.MonitorData.Chitunion.Bll.MonitorNotice.Interface;
using XYAuto.MonitorData.Chitunion.Infrastruct.Verification;

namespace XYAuto.MonitorData.Chitunion.Bll.MonitorNotice
{
    public class SendProvider : VerifyOperateBase
    {
        private readonly SendDto _sendDto;
        private Dictionary<string, Func<string, ReturnValue>> _dictionary;//前台页面查询接口泛型集合

        public SendProvider(SendDto sendDto)
        {
            _sendDto = sendDto;
            InitDic(_sendDto);
        }

        private void InitDic(SendDto sendDto)
        {
            _dictionary = new Dictionary<string, Func<string, ReturnValue>>()
            {
                { "notice.weixin", s => new SendByWeiXinProvider(sendDto).Send()},
                { "notice.mobileMsg", s => new SendByMobileMsgProvider(sendDto).Send()},
                { "notice.email", s => new SendByEmailProvider(sendDto).Send()}
            };
        }

        public static string GetSendKey(SendNoticeEnum sendNotice)
        {
            var sendDic = new Dictionary<SendNoticeEnum, string>()
            {
                { SendNoticeEnum.微信,"notice.weixin"},
                 { SendNoticeEnum.短信,"notice.mobileMsg"},
                  { SendNoticeEnum.邮件,"notice.email"}
            };

            return sendDic.ContainsKey(sendNotice)
                ? sendDic[sendNotice]
                : string.Empty;
        }


        public ReturnValue ToSend()
        {
            if (string.IsNullOrWhiteSpace(_sendDto.ToUser))
            {
                return CreateFailMessage(new ReturnValue(), "1001", "_sendDto.ToUser is empty");
            }

            return _dictionary.ContainsKey(_sendDto.NoticeKey)
                    ? _dictionary[_sendDto.NoticeKey].Invoke(string.Empty)
                    : CreateFailMessage(new ReturnValue(), "1002", "_sendDto.NoticeKey is not find");
        }

    }
}
